#ifndef BRANCH_CONTOUR_H_INCLUDED
#define BRANCH_CONTOUR_H_INCLUDED

#include "miscellaneous.h"
#include "image.h"
#include "morphology.h"
#include "core.h"
#include "contour.h"
#include "branchs.h"
#include <iostream>

/**\file contour_extractor.h
*  \brief Define the object that extract the contour of an image */

/** \class ContourExtractor
*   \brief This class define the object that extract the contour of an Image(Grey or Binary)
*/

class ContourExtractorBranch{
    public:

        ///Get the contour of a Binary_Image
        ///Must be a unique connected shape
        ///\param image Pointer to Binary_Image
        ///\return Pointer to extracted Contour
        Contour* getContour(Grey_Image *rotuled,PositionMap *pointer);
    private:

        ///Height of image contoured
        int height;
        ///Width of image contoured
        int width;
        ///Direction of previous to next pixel in chain-code
        int d_pc;
        ///Direction of previous to next pixel in chain-code
        int d_cn;
        ///First point of contour
        Position first;
        ///Current point of contour
        Position current;
        ///Next Point of contour
        Position next;
        ///Create relative positions for neighbours
        Position *neighbours;

        Position dontrepeat;

        ///
        int lastlabel;
        int currlabel;
        int lastanteriorlabel;

        Position currobjpix;
        Position lastobjpix;



        bool crossing;

        Position continuepoint;

        ///Function which invert the chain-code
        ///\param code The code which will be inverted
        int invertChainCode(int code);

        ///Find first point of contour
        ///\param image Pointer to Binary_Image
        ///\return The first point of contour
        Position findFirstPoint(Grey_Image *rotuled);


        ///Find next point of contour
        ///\param image Pointer to Binary_Image
        ///\return The next point of contour
        Position findNextPoint(Grey_Image *rotuled,bool crossingout);

        void bresenham(Contour* contour,Position first,Position last);


        ///Get the contour of a Binary_Image
        ///Must be a unique connected shape
        ///\param image Pointer to Binary_Image
        ///\return Pointer to extracted Contour
        Contour* contourFollower(Grey_Image *rotuled,PositionMap *pointer);


};


#endif // BRANCH_CONTOUR_H_INCLUDED
